#ifndef _SKFAPI_H_
#define _SKFAPI_H_

typedef signed char         INT8;
typedef signed short        INT16;
typedef signed int          INT32;
typedef unsigned char       UINT8;
typedef unsigned short      UINT16;
typedef unsigned int	    UINT32;

typedef UINT8				BYTE;
typedef char				CHAR;
typedef INT16				SHORT;
typedef UINT16				USHORT;
typedef long				LONG;
typedef unsigned long		ULONG;
typedef UINT32				UINT;
typedef UINT16				WORD;
typedef unsigned long		DWORD;
typedef UINT32				FLAGS;
typedef CHAR* LPSTR;
typedef void* HANDLE;
typedef int					BOOL;

typedef HANDLE				DEVHANDLE;
typedef HANDLE				HAPPLICATION;
typedef HANDLE				HCONTAINER;

#define DEVAPI  //__stdcall

#define SAR_OK							0x00000000	//成功
#define SAR_FAIL						0x0A000001	//失败
#define SAR_UNKNOWNERR					0x0A000002	//异常错误
#define SAR_NOTSUPPORTYETERR			0x0A000003	//不支持的服务
#define SAR_FILEERR						0x0A000004	//文件操作错误
#define SAR_INVALIDHANDLEERR			0x0A000005	//无效的句柄
#define SAR_INVALIDPARAMERR				0x0A000006	//无效的参数
#define SAR_READFILEERR					0x0A000007	//读文件错误
#define SAR_WRITEFILEERR				0x0A000008	//写文件错误
#define SAR_NAMELENERR					0x0A000009	//名称长度错误
#define SAR_KEYUSAGEERR					0x0A00000A	//密钥用途错误
#define SAR_MODULUSLENERR				0x0A00000B	//模的长度错误
#define SAR_NOTINITIALIZEERR			0x0A00000C	//未初始化
#define SAR_OBJERR						0x0A00000D	//对象错误
#define SAR_MEMORYERR					0x0A00000E	//内存错误
#define SAR_TIMEOUTERR					0x0A00000F	//超时
#define SAR_INDATALENERR				0x0A000010	//输入数据长度错误
#define SAR_INDATAERR					0x0A000011	//输入数据错误
#define SAR_GENRANDERR					0x0A000012	//生成随机数错误
#define SAR_HASHOBJERR					0x0A000013	//HASH对象错误
#define SAR_HASHERR						0x0A000014	//HASH运算错误
#define SAR_GENRSAKEYERR				0x0A000015	//产生RSA密钥错误
#define SAR_RSAMODULUSLENERR			0x0A000016	//RSA密钥模长错误
#define SAR_CSPIMPRTPUBKEYERR			0x0A000017	//CSP服务导入公钥错误
#define SAR_RSAENCERR					0x0A000018	//RSA加密错误
#define SAR_RSADECERR					0x0A000019	//RSA解密错误
#define SAR_HASHNOTEQUALERR				0x0A00001A	//HASH值不相等
#define SAR_KEYNOTFOUNTERR				0x0A00001B	//未发现密钥
#define SAR_CERTNOTFOUNTERR				0x0A00001C	//未发现证书
#define SAR_NOTEXPORTERR				0x0A00001D	//对象未导出
#define SAR_DECRYPTPADERR				0x0A00001E	//解密时做补丁错误
#define SAR_MACLENERR					0x0A00001F	//MAC长度错误
#define SAR_BUFFER_TOO_SMALL			0x0A000020	//缓冲区不足
#define SAR_KEYINFOTYPEERR				0x0A000021	//密钥类型错误
#define SAR_NOT_EVENTERR				0x0A000022	//无事件错误
#define SAR_DEVICE_REMOVED				0x0A000023	//设备已移除
#define SAR_PIN_INCORRECT				0x0A000024	//PIN错误
#define SAR_PIN_LOCKED					0x0A000025	//PIN锁死
#define SAR_PIN_INVALID					0x0A000026	//PIN无效
#define SAR_PIN_LEN_RANGE				0x0A000027	//PIN长度错误
#define SAR_USER_ALREADY_LOGGED_IN		0x0A000028	//用户已经登录
#define SAR_USER_PIN_NOT_INITIALIZED	0x0A000029	//没有初始化用户口令
#define SAR_USER_TYPE_INVALID			0x0A00002A	//PIN类型错误
#define SAR_APPLICATION_NAME_INVALID	0x0A00002B	//应用名称无效
#define SAR_APPLICATION_EXISTS			0x0A00002C	//应用已经存在
#define SAR_USER_NOT_LOGGED_IN			0x0A00002D	//用户没有登录
#define SAR_APPLICATION_NOT_EXISTS		0x0A00002E	//应用不存在
#define SAR_FILE_ALREADY_EXIST			0x0A00002F	//文件已经存在
#define SAR_NO_ROOM						0x0A000030	//存储空间不足
#define SAR_FILE_NOT_EXIST				0x0A000031	//文件不存在
#define SAR_REACH_MAX_CONTAINER_COUNT	0x0A000032	//已达到最大可管理容器数
#define SAR_LOAD_LIBRARY_FAIL		    0x0A00003B  //加载设备库失败
#define SAR_ENUM_DEVICE_FAIL		    0x0A00003C  //枚举不到设备
#define SAR_X509_D2IX509_FAIL		    0x0A00003D  //解析证书失败
#define SAR_MALLOC_MEMORYERR 		    0x0A00003E  //申请内存失败

#define SAR_SECURITY_INVALID			0x0B000033	//安全状态不满足
#define SAR_OFFSET_VOER_FILE			0x0B000034	//指针移到超过文件长度
#define SAR_CONTAINER_NOT_FOUND			0x0B000035	//容器不存在
#define SAR_CONTAINER_EXIST				0x0B000036	//容器已存在
#define SAR_AUTH_LOCKED					0x0B000037	//设备认证锁定
#define SAR_ECCENCERR					0x0B000038	//ECC加密错误

#define	ADMIN_TYPE				0x00000000	// 管理员PIN
#define USER_TYPE				0x00000001	// 用户PIN

typedef struct ERR_string_data_st {
    unsigned long error;
    const char* string;
} ERR_STRING_DATA;

static ERR_STRING_DATA SKF_str_reasons_zh_CN_UTF8[] = {
    {SAR_OK,			"成功"},
    {SAR_FAIL,			"失败"},
    {SAR_UNKNOWNERR,			"异常错误"},
    {SAR_NOTSUPPORTYETERR,		"不支持的服务"},
    {SAR_FILEERR,			"文件操作错误"},
    {SAR_INVALIDHANDLEERR,		"无效的句柄"},
    {SAR_INVALIDPARAMERR,		"无效的参数"},
    {SAR_READFILEERR,			"读文件错误"},
    {SAR_WRITEFILEERR,			"写文件错误"},
    {SAR_NAMELENERR,			"名称长度错误"},
    {SAR_KEYUSAGEERR,			"密钥用途错误"},
    {SAR_MODULUSLENERR, 		"模的长度错误"},
    {SAR_NOTINITIALIZEERR , 		"未初始化"},
    {SAR_OBJERR,			"对象错误"},
    {SAR_MEMORYERR, 		"内存错误"},
    {SAR_TIMEOUTERR,			"超时"},
    {SAR_INDATALENERR,			"输入数据长度错误"},
    {SAR_INDATAERR, 		"输入数据错误"},
    {SAR_GENRANDERR,			"生成随机数错误"},
    {SAR_HASHOBJERR,			"HASH对象错误"},
    {SAR_HASHERR,			"HASH运算错误"},
    {SAR_GENRSAKEYERR,			"产生RSA密钥错误"},
    {SAR_RSAMODULUSLENERR,			"RSA密钥模长错误"},
    {SAR_CSPIMPRTPUBKEYERR, 		"CSP服务导入公钥错误"},
    {SAR_RSAENCERR, 		"RSA加密错误"},
    {SAR_RSADECERR, 		"RSA解密错误"},
    {SAR_HASHNOTEQUALERR,			"HASH值不相等"},
    {SAR_KEYNOTFOUNTERR,			"未发现密钥"},
    {SAR_CERTNOTFOUNTERR,			"未发现证书"},
    {SAR_NOTEXPORTERR,			"对象未导出"},
    {SAR_DECRYPTPADERR, 		"解密时做补丁错误"},
    {SAR_MACLENERR, 		"MAC长度错误"},
    {SAR_BUFFER_TOO_SMALL,			"缓冲区不足"},
    {SAR_KEYINFOTYPEERR,			"密钥类型错误"},
    {SAR_NOT_EVENTERR,			"无事件错误"},
    {SAR_DEVICE_REMOVED,			"设备已移除"},
    {SAR_PIN_INCORRECT, 		"PIN不正确"},
    {SAR_PIN_LOCKED,			"PIN被锁死"},
    {SAR_PIN_INVALID,			"PIN无效"},
    {SAR_PIN_LEN_RANGE, 		"PIN长度错误"},
    {SAR_USER_ALREADY_LOGGED_IN,			"用户已经登录"},
    {SAR_USER_PIN_NOT_INITIALIZED,			"没有初始化用户口令"},
    {SAR_USER_TYPE_INVALID, 		"PIN类型错误"},
    {SAR_APPLICATION_NAME_INVALID,			"应用名称无效"},
    {SAR_APPLICATION_EXISTS,			"应用已经存在"},
    {SAR_USER_NOT_LOGGED_IN,			"用户没有登录"},
    {SAR_APPLICATION_NOT_EXISTS,			"应用不存在"},
    {SAR_FILE_ALREADY_EXIST,			"文件已经存在"},
    {SAR_NO_ROOM,			"存储空间不足"},
    {SAR_FILE_NOT_EXIST,			"文件不存在"},
    {SAR_REACH_MAX_CONTAINER_COUNT, 		"已达到最大可管理容器数"}, //0x0A000032
    {SAR_LOAD_LIBRARY_FAIL, 		"加载设备库失败"},
    {SAR_ENUM_DEVICE_FAIL, 			"枚举不到设备"},
    {SAR_X509_D2IX509_FAIL, 		"解析证书失败"},
    {SAR_MALLOC_MEMORYERR, 			"申请内存失败"},
};


ULONG SKF_UsbKeyVerifyPin(char *lib_path, char* userPin);
ULONG SKF_UsbKeyModPin(char *lib_path, char* oldUserPin, char* newUserPin);
ULONG SKF_GetErrorString(ULONG ulError, char* szErrorStr);

#endif //_SKFAPI_H_

